package SocketTool;

import java.awt.Robot;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class PPTServer {
	public static void init(){
		byte[] buff = new byte[1024];
		DatagramPacket dp = new DatagramPacket(buff, buff.length);
		DatagramSocket ds =null;
		try {
			String info = "";
			ds = new DatagramSocket(5800);
			while (true) {
				ds.receive(dp);
				byte[] sz=dp.getData();
				info =new String(sz, 0,dp.getLength());
				if (info.equalsIgnoreCase("quit")) {
					System.out.println("�������!");
					break;
				}
				else {
					System.out.println("ppt������"+info);
					if (info.equals("N")) {
						KeyRobot.sendKey(2);
					}
					if (info.equals("P")) {
						KeyRobot.sendKey(1);
					}
					if (info.equals("F5")) {
						KeyRobot.sendKey(0);
					}
					
				}
			}
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		finally{
			ds.close();
		}
	}
	public static void main(String[] args) {
		PPTServer.init();
	}
}
